package com.hnkywl.sts.service.flow;

import com.hnkywl.sts.dao.flow.LcpzDao;
import com.hnkywl.sts.entity.flow.FlowConfigure;
import com.hnkywl.sts.util.BaseUtils;
import net.ruixin.orm.hibernate.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: lenovo
 * Date: 13-6-16
 * Time: 下午5:14
 * To change this template use File | Settings | File Templates.
 */
@Service
public class LcpzService {
    private LcpzDao  lcpzDao;
          //流程配置列表显示
    @Transactional
    public String findAllLcpz(String name,int pageNo, int pageSize) {
        Page<FlowConfigure> lcpzPage = this.lcpzDao.findLcpzList(name, pageNo, pageSize);
        List<FlowConfigure> lcpzList = lcpzPage.getResult() == null ? new ArrayList<FlowConfigure>() :lcpzPage.getResult();
        String lcpzJson = BaseUtils.fetchCollectionToJson(lcpzList, "id", "flowName",  "flowStart");
        return "{\"total\":" + lcpzPage.getTotalCount() + ",\"rows\":[" + lcpzJson + "]}";
    }
    @Transactional
    public FlowConfigure findLcpzDetail(Long id) {
        return this.lcpzDao.get(id);
    }

    @Transactional
    public void changeStatus(Long id, Boolean  status) {
        FlowConfigure lcpz = this.findLcpzDetail(id);
        lcpz.setFlowStart(status);
        this.lcpzDao.save(lcpz);
    }
    @Autowired
    public void setLcpzDao(LcpzDao lcpzDao) {
        this.lcpzDao = lcpzDao;
    }
}
